package de.placidi.pressreview.parsing;


/**
 * A word with its number of occurencies. 
 * 
 * @author Alexander Placidi
 *
 */
public final class CountedWord implements Comparable<CountedWord>{
	
	private String word;
	private Integer frequency;
	
	public CountedWord(String word, Integer frequency) {
		this.word = word;
		this.frequency = frequency;
	}
	
	public void incrementFrequency() {
		frequency++;
	}

	public String getWord() {
		return word;
	}

	public Integer getFrequency() {
		return frequency;
	}
	
	public void setFrequency(Integer frequency) {
		this.frequency = frequency;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((word == null) ? 0 : word.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		CountedWord other = (CountedWord) obj;
		if (word == null) {
			if (other.word != null)
				return false;
		} else if (!word.equals(other.word))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "CountedWord [word=" + word + ", frequency=" + frequency + "]";
	}

	@Override
	public int compareTo(CountedWord o) {
		int f = o.getFrequency();
		
		if (this.getFrequency() < f) {
			return 1;
		} else if (this.getFrequency() > f) {
			return -1;
		}
		
		return 0;
	}

	
	
}
